package com.ac.scum.log.web.model.pack.mapper;

import com.ac.scum.log.bean.Package;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PackageMapper extends BaseMapper<Package> {

    @Insert("insert into package_menu values ( #{packageId} , #{menuId} )")
    void joinMenu(@Param("packageId") Long packageId, @Param("menuId") Long menuId);

    @Delete("delete from package_menu where package_id = #{packageId} and menu_id = #{menuId}")
    void quitMenu(@Param("packageId") Long packageId, @Param("menuId") Long menuId);

    @Select("select * from package p inner join server_package sp on sp.package_id = p.id where sp.server_id = #{serverId}")
    List<Package> selectByServerId(@Param("serverId") Long serverId);
    @Select("select * from package p inner join server_package sp on sp.package_id = p.id where sp.server_id = #{serverId} and sp.package_id = #{packageId} limit 1")
    Package selectByServerIdAndPackageId(@Param("serverId") Long serverId, @Param("packageId") Long packageId);
    @Insert("insert into server_package value (#{pack.serverId},#{pack.id},#{pack.expirationTime})")
    void insertPackageAsServer(@Param("pack") Package pack);
    @Update("update server_package set expiration_time = #{pack.expirationTime} where server_id = #{pack.serverId} and package_id = #{pack.id}")
    void updatePackageAsServer(@Param("pack") Package pack);


    @Select("select * from package p inner join player_package sp on sp.package_id = p.id where sp.steam_id = #{steamId}")
    List<Package> selectBySteamId(@Param("steamId") Long steamId);
    @Select("select * from package p inner join player_package sp on sp.package_id = p.id where sp.steam_id = #{steamId}  and sp.package_id = #{packageId} limit 1")
    Package selectBySteamIdAndPackageId(@Param("steamId") Long steamId, @Param("packageId") Long packageId);
    @Insert("insert into player_package value (#{pack.playerId},#{pack.steamId},#{pack.serverId},#{pack.id},#{pack.expirationTime})")
    void insertPackageAsPlayer(@Param("pack") Package pack);
    @Update("update player_package set expiration_time = #{pack.expirationTime} where player_id = #{pack.playerId} and package_id = #{pack.id}")
    void updatePackageAsPlayer(@Param("pack") Package pack);
}
